package com.fjrz.bbxwj.main.host

import com.blankj.utilcode.util.BarUtils
import com.blankj.utilcode.util.FragmentUtils
import com.module.lemlin.base.BaseAbstractFragment
import com.fjrz.bbxwj.R
import com.fjrz.bbxwj.app.RZApplication
import com.fjrz.bbxwj.entity.User
import com.fjrz.bbxwj.entity.UserMe
import com.fjrz.bbxwj.main.mine.UserInfoFragment
import com.module.lemlin.view.LoginAuthPopup
import kotlinx.android.synthetic.main.fragment_main_mine.*

class MainMineFragment : BaseAbstractFragment() {

    companion object {
        fun newInstance(): MainMineFragment {
            return MainMineFragment()
        }
    }

    override val layoutResId: Int
        get() = R.layout.fragment_main_mine

    override fun initView() {

        BarUtils.addMarginTopEqualStatusBarHeight(flMainMineBar)

    }

    override fun initData() {

        val userMe: UserMe? = RZApplication.userInfoMe()

        val user: User = if (userMe == null) {
            User(
                id = 0, nickname = "未登录", introduction = "个人简介",
                avatar = "", who = User.Who.USER_ME
            )
        } else User(
            id = userMe.id, nickname = userMe.nickname, introduction = userMe.introduction,
            avatar = userMe.avatar, who = User.Who.USER_ME
        )
        FragmentUtils.replace(
            childFragmentManager, UserInfoFragment.newInstance(user), R.id.flMainMineBody
        )
    }

    override fun onEventMainThread(any: Any) {
        if (any !is LoginAuthPopup.Action)
            return
        if (any == LoginAuthPopup.Action.ACTION_LOGIN_SUCCESS) {
            initData()
        }
    }

}